package com.example.movie.mate.controller;

import com.example.movie.mate.pojo.core.Principle;
import com.example.movie.mate.pojo.param.BookingAddNewParam;
import com.example.movie.mate.pojo.vo.BookingFullInfoVO;
import com.example.movie.mate.pojo.vo.BookingSimpleInfoVO;
import com.example.movie.mate.service.IBookingService;
import com.example.movie.mate.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpSession;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 订单控制器
 */
@Tag(name = "6. 订单管理模块")
@RestController
@RequestMapping("/api/booking")
public class BookingController {

    @Autowired
    private IBookingService bookingService;

    @Operation(summary = "[用户] 新增订单")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@ParameterObject BookingAddNewParam param, HttpSession session) {
        Principle principle = (Principle) session.getAttribute(Principle.SESSION_KEY);
        bookingService.addNew(param, principle);
        return JsonResult.ok();
    }

    @Operation(summary = "[用户] 根据ID查询订单详情")
    @ApiOperationSupport(order = 410)
    @Parameter(name = "id", description = "订单id", required = true, example = "1")
    @PostMapping("/{id}")
    public JsonResult<BookingFullInfoVO> selectFullInfoByIdAndUser(@PathVariable Long id, HttpSession session) {
        Principle principle = (Principle) session.getAttribute(Principle.SESSION_KEY);
        BookingFullInfoVO bookingFullInfo = bookingService.selectFullInfoByIdAndUser(id, principle);
        return JsonResult.ok(bookingFullInfo);
    }

    @Operation(summary = "[用户] 查询所有订单列表")
    @ApiOperationSupport(order = 420)
    @PostMapping("")
    public JsonResult<List<BookingSimpleInfoVO>> selectSimpleInfoByUser(HttpSession session) {
        Principle principle = (Principle) session.getAttribute(Principle.SESSION_KEY);
        List<BookingSimpleInfoVO> list = bookingService.selectSimpleInfoByUser(principle);
        return JsonResult.ok(list);
    }

}